package com.zchat.android.widget;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.zchat.android.R;
import com.zchat.android.WelcomeActivity;

public class ScrollPageControlView extends LinearLayout{

	private int count;

	private Context context;
	private Activity activity;

	public void setCount(int count) {
		this.count = count;
	}

	public ScrollPageControlView(Context context, AttributeSet attrs) {
		super(context, attrs);
		this.init(context);
	}

	public ScrollPageControlView(Context context) {
		super(context);
		this.init(context);
	}

	private void init(Context context) {
		this.context = context;
	}


	public void generatePageControl(int currentIndex) {
		this.removeAllViews();

		for (int i = 0; i < this.count; i++) {
			ImageView imageView = new ImageView(context);
			if (currentIndex == i) {
				imageView.setImageResource(R.drawable.page_indicator_focused);
			} else {
				imageView.setImageResource(R.drawable.page_indicator);
			}
			this.addView(imageView);
		}
	}

	public void setActivity(Activity activity) {
		this.activity = activity;
	}
	
	public void toIntent() {
		if(activity != null) {
	    	Intent welcome = new Intent(context, WelcomeActivity.class);
	    	context.startActivity(welcome);
	    	activity.finish();
		}
	}
}
